package com.ruoyi.controller;
import com.ruoyi.domain.common.ResponseResult;
import com.ruoyi.utils.AliOssUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;

/**
 * 上传文件存入阿里云
 */
@Slf4j
@RestController
public class UploadController {

    @Autowired
    private AliOssUtils aliOssUtils;

    @PostMapping("/upload")
    public ResponseResult<String> upload(@RequestBody MultipartFile image) throws IOException {
        //调用阿里云OSS工具类，将上传上来的文件存入阿里云
        String url = aliOssUtils.upload(image);
        //将图片上传完成后的url返回，用于浏览器回显展示
        return ResponseResult.success(url,"操作成功");
    }

}

